package com.example.demo.service.impl;

import com.example.demo.dao.CourseChaptsDao;
import com.example.demo.dao.UserDao;
import com.example.demo.entity.CourseChaptsBean;
import com.example.demo.entity.UserBean;
import com.example.demo.service.CourseChaptsService;
import com.example.demo.service.UserService;
import com.example.demo.util.JwtUtil;
import com.example.demo.util.PageEntity;
import com.example.demo.util.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.soap.Text;
import java.util.HashMap;
import java.util.List;

import static java.awt.SystemColor.text;

@Service
public class CourseChaptsServiceImpl   implements CourseChaptsService {

    @Autowired
    private CourseChaptsDao courseChaptsDao;

    @Override
    public List<CourseChaptsBean> all() {
        return courseChaptsDao.getAll();
    }

    @Override
    public Integer add(CourseChaptsBean courseChaptsBean) {
        return courseChaptsDao.insert(courseChaptsBean);
    }


    @Override
    public Integer update(CourseChaptsBean courseChaptsBean) {
        return courseChaptsDao.edit(courseChaptsBean);
    }

    @Override
    public Integer delete(Integer id) {
        return courseChaptsDao.del(id);
    }

    @Override
    public CourseChaptsBean one(Integer id) {
        return courseChaptsDao.getOne(id);
    }

    @Override
    public PageEntity list(Integer pageNo, Integer pageSize,String name, String sortOrder) {

        // 根据页码 求 跳过多少条数据
        Integer jump = (pageNo-1)*pageSize;
        Integer count = courseChaptsDao.getCount(name);

        List<CourseChaptsBean> rows = courseChaptsDao.getPage(jump, pageSize,name, sortOrder);


        PageEntity<List> listPageEntity = new PageEntity<List>(rows,count);
        return listPageEntity;
    }

}

